#include<iostream>
#include<string>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<vector>
#include<stdlib.h>
#include<cstring>
#include<errno.h>
#include<algorithm>
using namespace std;

string check(" \t");

string pwd()
{
  string s = getenv("PWD");
  size_t pos = s.rfind('/');
  return string(s.begin() + pos + 1,s.end());
}

vector<string> handle(string nums)
{
  vector<string> ans;
  string t;
  for (auto ch : nums)
  {
    if (check.find(ch) != string::npos)
    {
      ans.push_back(t);
      t = "";
    }
    else 
    {
      t += ch;
    }
  }
  ans.push_back(t);
  return ans;
}


int main()
{
  while (true)
  {
    printf("[%s@%s %s]%c", getenv("USER"), getenv("HOSTNAME"), pwd().c_str(), (string(getenv("USER")) == "root" ? '#' : '$'));

    string nums;
    getline(cin, nums);

    vector<string> command = handle(nums);
    if (command.empty())
    {
      continue;
    }

    vector<char*> argv;
    for (auto& s : command)
    {
      argv.push_back(const_cast<char*>(s.c_str()));
    }
    argv.push_back(nullptr);
    
    pid_t pid = fork();
    if (pid == 0)
    {  
      int t = execvp(argv[0], argv.data());
      if (t == -1)
      {
        cout<<strerror(2)<<endl;
      }
    }
    else 
    {
      pid_t e = wait(nullptr);
      if (e == -1)
      {
        cout<<strerror(errno)<<endl;
      }
    }
  }
  return 0;
}
